﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using DomainDriver.DomainModeling.DataProviders;
using DomainDriver.DomainModeling.GenericUnitTesting.Constraints;
using AutomotivePricingModel.Brands;
using AutomotivePricingModel.Dealers;

namespace AutomotivePricingModel.UnitTests.ListRelationConstraints
{
    [TestFixture(new object[] { DataSourcePersistenceType.None })]
    [TestFixture(new object[] { DataSourcePersistenceType.File })]
    [TestFixture(new object[] { DataSourcePersistenceType.Database })]
    public class DealerBrandListRelationConstraintTests : ListRelationConstraintTestFixture<AutomotivePricingDomainModel, Guid, Guid, Dealer, Brand>
    {
        public DealerBrandListRelationConstraintTests(DataSourcePersistenceType persistenceType)
            : base(persistenceType)
        {
            // do nothing
        }

        protected override AutomotivePricingDomainModel CreateDomainModel(DataSourcePersistenceType persistenceType, bool buildModelWithConstraints)
        {
            AutomotivePricingDomainModel model = new AutomotivePricingDomainModel(persistenceType, buildModelWithConstraints);
            return model;
        }

        protected override Dealer CreateOwner()
        {
            Dealer owner = new Dealer();
            owner.Name = owner.Key.ToString();
            return owner;
        }

        protected override Brand CreateElement()
        {
            Brand element = new Brand();
            element.Name = element.Key.ToString();
            return element;
        }

        protected override void AddToList(Dealer owner, Guid elementKey)
        {
            owner.AddBrand(elementKey);
        }

        protected override void RemoveFromList(Dealer owner, Guid elementKey)
        {
            owner.RemoveBrand(elementKey);
        }

        protected override void ClearList(Dealer owner)
        {
            foreach (Guid elementKey in owner.BrandsRepresented)
            {
                owner.RemoveBrand(elementKey);
            }
        }

        protected override int ListCount(Dealer owner)
        {
            return owner.BrandsRepresented.Count;
        }

        protected override bool ListContains(Dealer owner, Guid elementKey)
        {
            return owner.BrandsRepresented.Contains(elementKey);
        }
    }
}